package com.esms.controller.log;

import com.esms.dao.EmployeeMapper;
import com.esms.po.Employee;
import com.esms.po.LogValue;
import com.esms.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @author : [ok]
 * @version : [v1.0]
 * @description : [一句话描述该类的功能]
 * @createTime : [2022/3/21 23:14]
 * @updateUser : [ok]
 * @updateTime : [2022/3/21 23:14]
 * @updateRemark : [说明本次修改内容]
 */
@Controller
@RequestMapping("/saveMenuLog")
public class SaveMenuLogController {

	@Autowired
	private EmployeeMapper employeeMapper = null;
	@Autowired
	public com.esms.service.ILogService ILogService;


	/**
	 * 保存菜单点击事件日志记录
	 * @param httpSession
	 * @return
	 */

	@RequestMapping("/saveMenuClickLogInfo.do")
	@ResponseBody
	public Message clickMenuInfo(HttpSession httpSession,String flag) throws Exception {

		Timestamp date = new Timestamp(new Date().getTime());
		String method = "clickMenuInfo";

		int eId = (Integer) httpSession.getAttribute("employeeId");
		Employee employee = employeeMapper.selectByPrimaryKey(eId);
		String account = employee.geteAccount();
		String menuName = getMenuNameforFlag(flag);
		try {
			//记录登录成功日志
			String value = "工号"+account+"员工，于"+date+"点击了"+menuName+"菜单!";
			insertLogRecord(account,value,date,method);
		}catch(Exception e) {
			e.printStackTrace();
		}

		return Message.success("success");
	}


	/**
	 * 登录日志记录操作
	 * **/
	public void insertLogRecord(String account, String value, Timestamp date, String method){
		LogValue record = new LogValue();
		record.setLogAccount(account);
		record.setLogClass(this.getClass().getName());
		record.setLogMethod(method);
		record.setLogValue(value);
		record.setCreateTime(date);
		record.setUpdateTime(date);
		ILogService.insert(record);
	}

	/**
	 * 根据前端传入的flag赋值对应的标签
	 * **/
	public static String getMenuNameforFlag(String flag){
		String menuName = "";
		if("1".equals(flag)){
			menuName = "个人信息";
		}else if("2".equals(flag)){
			menuName = "同级测评";
		}else if("3".equals(flag)){
			menuName = "下级对上级测评";
		}else if("4".equals(flag)){
			menuName = "上级对下级测评";
		}else if("5".equals(flag)){
			menuName = "满意度测评";
		}else if("6".equals(flag)){
			menuName = "周纪实信息录入";
		}else if("7".equals(flag)){
			menuName = "周纪实信息审核";
		}else if("8".equals(flag)){
			menuName = "工作业绩考核";
		}else if("9".equals(flag)){
			menuName = "出勤考核";
		}else if("10".equals(flag)){
			menuName = "加分项考核";
		}else if("11".equals(flag)){
			menuName = "考核结果";
		}else if("12".equals(flag)){
			menuName = "科室职责";
		}else if("13".equals(flag)){
			menuName = "备用2";
		}else if("14".equals(flag)){
			menuName = "备用3";
		}else if("15".equals(flag)){
			menuName = "备用4";
		}else{
			menuName = "备用5";
		}
		return menuName;
	}

}
